//
//  AppSexView.m
//  i5db
//
//  Created by iMuse on 15-5-12.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "AppSexView.h"
#import "AppCenter.h"

@implementation AppSexView
{
    UIView      * contentView;
    UIButton    * manButton;
    UIButton    * womanButton;
}

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code
        [self initView];
    }
    return self;
}

-(void)initView
{

    UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeSelf:)];
    [self addGestureRecognizer:gesture];
    
    UIImageView* imageView = [UIImageView newAutoLayoutView];
    imageView.backgroundColor = [UIColor blackColor];
    imageView.alpha = 0.4;
    [self addSubview:imageView];
    [imageView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    
    contentView = [UIView newAutoLayoutView];
    contentView.backgroundColor = [UIColor whiteColor];
    [self addSubview:contentView];
    [contentView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [contentView autoAlignAxisToSuperviewAxis:ALAxisVertical];
    [contentView autoSetDimensionsToSize:CGSizeMake(200, 120)];
    
    manButton = [UIButton newAutoLayoutView];
    [manButton setTitle:@"男" forState:UIControlStateNormal];
    [manButton addTarget:self action:@selector(selectSex:) forControlEvents:UIControlEventTouchUpInside];
    manButton.titleLabel.font = [UIFont systemFontOfSize:17];
    [manButton setTitleColor:[AppCenter color:@"76,187,248,1"] forState:UIControlStateNormal];
    [contentView addSubview:manButton];
    [manButton autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 60, 0)];
    
    UILabel* line = [UILabel newAutoLayoutView];
    line.backgroundColor = [AppCenter color:@"188,188,188,1"];
    [contentView addSubview:line];
    
    [line autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:manButton];
    [line autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [line autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
    [line autoSetDimension:ALDimensionHeight toSize:0.3];
    
    womanButton = [UIButton newAutoLayoutView];
    [womanButton setTitle:@"女" forState:UIControlStateNormal];
    [womanButton addTarget:self action:@selector(selectSex:) forControlEvents:UIControlEventTouchUpInside];
    [womanButton setTitleColor:[AppCenter color:@"76,187,248,1"] forState:UIControlStateNormal];
    [contentView addSubview:womanButton];
    [womanButton autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:line withOffset:0];
    [womanButton autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
    [womanButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [womanButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    
    
}





-(void)removeSelf:(id)sender
{
    [self removeFromSuperview];
}
-(void)selectSex:(UIButton*)button
{
    if ([self.delegate respondsToSelector:@selector(onTapSelectSex:)])
    {
        [self.delegate performSelector:@selector(onTapSelectSex:) withObject:button.titleLabel.text];
    }
    [self removeFromSuperview];
}

@end
